import type { CreateFlowInput } from '@/app/api/flows/route';
import { clientFetch } from '@/utils/request';

export const sendCreateFlow = async ({
  code,
  imageUrl,
  name,
}: CreateFlowInput) => {
  try {
    const res = await clientFetch.post('/api/flows', {
      code,
      name,
      imageUrl,
    });

    if (res.code !== 200) {
      throw new Error(`请求失败，错误信息：${res.message}`);
    }

    return res.data;
  } catch (error) {
    throw error;
  }
};

export const handleAddFlow = async (values: {
  code: string;
  name: string;
  imageUrl: string;
  aiAnalysisText: string;
}) => {
  try {
    const res = await clientFetch.post('/api/flows', {
      code: values.code,
      name: values.name,
      imageUrl: values.imageUrl,
      aiAnalysisText: values.aiAnalysisText,
    });

    return res;
  } catch (error) {
    console.error('Error adding flow:', error);
    throw error;
  }
};
